﻿@using AntDesign
@using lcwb.Shared.Service
@inject NoteDrawerService DrawerService
<Card>
    <div class="chat-container">
        <div class="chat-messages">
            @foreach (var msg in messages)
            {
                <div class="message @msg.Type">
                    <div class="content">@msg.Text</div>
                </div>
            }
        </div>
        <!-- 使用标准Input组件 + 按钮 -->
        <Row Gutter="8" Align="RowAlign.Middle">
            <Col Flex="@("1 1 200px")">
                <TextArea
                    @bind-Value="inputText"
                    Placeholder="输入消息..."
                    Rows="8"
                />
            </Col>
            <Col>
                <Button Type="ButtonType.Primary" OnClick="SendMessage">发送</Button>
            </Col>
        </Row>
    </div>
</Card>

<style>
.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    border-bottom: 1px solid #e8e8e8;
}

.message {
    margin: 8px 0;
    padding: 6px 12px;
    border-radius: 4px;
}

.user {
    text-align: right;
    background-color: #f0f0f0;
}

.bot {
    text-align: left;
    background-color: #e6fffa;
}
</style>

@code {
    private string inputText = "";
    private List<Message> messages = new List<Message>();

    protected override void OnInitialized()
    {
        messages.Add(new Message { Type = "bot", Text = "您好！我是AI助手。" });
    }

    private void SendMessage()
    {
        if (!string.IsNullOrEmpty(inputText))
        {
            messages.Add(new Message { Type = "user", Text = inputText });
            messages.Add(new Message { Type = "bot", Text = "GNU GCC（GNU Compiler Collection）是一套由自由软件基金会开发的编译器工具集，用于将高级语言（如C、C++、Fortran等）编写的源代码转换为机器可执行的二进制代码。" });
            inputText = ""; // 清空输入框
        }
    }

    private class Message
    {
        public string Type { get; set; }
        public string Text { get; set; }
    }
}